#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

void Swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}
void HeapSort(int* a, int n)
{
	int child = n - 1;
	int parent = (child - 1) / 2;
	while (child > 0)
	{
		if (a[child] < a[parent])
		{
			Swap(&a[child], &a[parent]);
			child = parent;
			parent = (child - 1) / 2;
		}
		else
		{
			break;
		}
	}
}

int main()
{
	int arr[10] = { 4,5,2,1,8,6,9,7,0,4 };
	for(int i=1;i<10;i++)
	{
		HeapSort(arr, i);
	}
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
}